<?php

namespace Design\Structural\DataMapper;

class UserMapper
{

    private $storage;


    public function __construct(StorageAdapter $storage)
    {
        $this->storage = $storage;

    }//end __construct()


    public function findById(int $id)
    {
        $data = $this->storage->get($id);

        if ($data === null) {
            throw new \InvalidArgumentException("User #$id not found.");
        }

        return $this->mapRowToUser($data);

    }//end findById()


    private function mapRowToUser(array $data)
    {
        return User::fromState($data);

    }//end mapRowToUser()


}//end class
